package cn.elricyu.kf.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import cn.elricyu.kf.util.DateUtil;

@Entity(name = "SnType")
@Table(name = "SnType")
@NamedQueries({
		@NamedQuery(name = "SnType.findSnTypeByAppName", query = "SELECT farm "
				+ "FROM SnType farm " + "WHERE farm.appName = :appName"),
		@NamedQuery(name = "SnType.findSnTypeByType", query = "SELECT farm "
				+ "FROM SnType farm " + "WHERE farm.type = :type"),
		@NamedQuery(name = "SnType.getAllSnType", query = "SELECT farms "
				+ "FROM SnType farms ORDER BY gmtCreate desc") })
public class SnType {
	public static long HOUR_TIME = 60 * 60 * 1000;
	public static long DAY_TIME = 24 * HOUR_TIME;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Long id;
	@Column(name = "type", nullable = false, length = 36)
	private String type;
	@Column(name = "appName", nullable = false, length = 36)
	private String appName;
	@Column(name = "price", nullable = false)
	private int price;
	@Column(name = "allowCount", nullable = false)
	private int allowCount;
	@Column(name = "dayTime", nullable = false)
	private long dayTime;
	@Column(name = "desc", length = 100)
	private String desc;
	@Column(name = "gmtCreate")
	private long gmtCreate;
	@Column(name = "gmtUpdate")
	private long gmtUpdate;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getAllowCount() {
		return allowCount;
	}

	public void setAllowCount(int allowCount) {
		this.allowCount = allowCount;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public long getDayTime() {
		return dayTime;
	}

	public long getDayTimeDesc() {
		return dayTime / DAY_TIME;
	}

	public void setDayTime(long dayTime) {
		this.dayTime = dayTime;
	}

	public long getGmtCreate() {
		return gmtCreate;
	}

	public void setGmtCreate(long gmtCreate) {
		this.gmtCreate = gmtCreate;
	}

	public long getGmtUpdate() {
		return gmtUpdate;
	}

	public void setGmtUpdate(long gmtUpdate) {
		this.gmtUpdate = gmtUpdate;
	}

	public String getGmtUpdateDesc() {
		if (gmtUpdate == 0) {
			return "";
		}
		return DateUtil.simpleFormat(gmtUpdate);
	}

	public String getGmtCreateDesc() {
		if (gmtCreate == 0) {
			return "";
		}
		return DateUtil.simpleFormat(gmtCreate);
	}
}
